<%@ page contentType="text/html;charset=UTF-8"%>
<%@page import="java.net.URL"%>
<%@page import="java.net.HttpURLConnection"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ include file="../common.jsp"%>
<%@ page import="cn.firstsoft.firstframe.admin.PropertyFile"%>
<%@ page import="org.springside.core.Constants" %>
<%@ page import="java.io.*,java.util.*,org.jdom.*,org.jdom.input.*,org.jdom.output.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%
	//得到当前的短信厂商


	String xmlFile = System.getProperty("oa_application.config") + "/cn/firstsoft/modules/message/applicationContext-message-manager.xml";
	File file = new File(xmlFile);
	SAXBuilder builder = new SAXBuilder();
	Document doc;
	String providerClass = "";
	try {
		doc = builder.build(file);
		Element beans = doc.getRootElement();
		List beanList = beans.getChildren("bean");
		
		for (int i=0; i<beanList.size(); i++) {
			Element bean = (Element)beanList.get(i);
			if ("commonSMSService".equals(bean.getAttributeValue("id"))) {
				providerClass = bean.getAttributeValue("class");
			}
			
		}
	} catch (JDOMException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	} catch (Exception e) {
		e.printStackTrace();
	}	
	
%>
<html>
<head>
<title>管理控制台 - 环境设置 - 手机集成</title>
<%@ include file="/common/meta2.jsp"%>
<link href="../style.css" type="text/css" rel=stylesheet>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
	<table width="100%" align="center" >
		<TR>
			<TH class=listViewPaginationTdS1  align=left colSpan=4>
			设置手机短信的集成参数


			</TH>
		</TR>
		<tr>
			<td class=dataLabel width="15%" align="right">手机短信厂商：</td>
			<td class=dataField>
				<select name="provider" size=1 onchange="changeProvider(this.options[this.selectedIndex].value+'Option');">
					<option value="">无短信集成</option>
					<!-- 先屏蔽掉短信猫

					<option value="Short" <%=providerClass.indexOf("sms.impl.Short")>0?"selected":"" %>>短信猫设备</option>-->
					<option value="Xuanwu" <%=providerClass.indexOf("sms.impl.Xuanwu")>0?"selected":"" %>>玄武短信(http://www.139130.net)</option>
					<option value="Ifly" <%=providerClass.indexOf("sms.impl.Ifly")>0?"selected":"" %>>金蝶IFLY(http://www.ifly.com.cn)</option>
					<option value="SouthSea" <%=providerClass.indexOf("sms.impl.SouthSea")>0?"selected":"" %>>佛山电信信息业务拓展中心</option>
					<option value="JassonSoft" <%=providerClass.indexOf("sms.impl.JassonSoft")>0?"selected":"" %>>深圳嘉讯(http://www.jassonsoft.com)</option>
					<option value="Mobset" <%=providerClass.indexOf("sms.impl.Mobset")>0?"selected":"" %>>广州首易(http://www.mobset.com)</option>
					<option value="Surge" <%=providerClass.indexOf("sms.impl.Surge")>0?"selected":"" %>>巨澜短信(http://www.surge.com.cn)</option>
					<option value="Weina" <%=providerClass.indexOf("sms.impl.Weina")>0?"selected":"" %>>维那短信(http://kingdee.weinaduo.net)</option>
					<option value="YouShang" <%=providerClass.indexOf("sms.impl.YouShang")>0?"selected":"" %>>友商短信(https://api.youshang.com)</option>
				</select>
			</td>
			<td align="left">不同的厂商的配置将不同</td>
		</tr>
		<script language="javascript">
			function changeProvider(p) {
				var dis = <%="".equals(providerClass)?"true":"false" %>;
				
				document.getElementById('Option').style.display='none';
				document.getElementById('ShortOption').style.display='none';
				document.getElementById('XuanwuOption').style.display='none';
				document.getElementById('IflyOption').style.display='none';
				document.getElementById('SouthSeaOption').style.display='none';
				document.getElementById('JassonSoftOption').style.display='none';
				document.getElementById('MobsetOption').style.display='none';
				document.getElementById('SurgeOption').style.display='none';
				document.getElementById('WeinaOption').style.display='none';
				document.getElementById('YouShangOption').style.display='none';
				//都显示提交按钮
				document.getElementById(p).style.display='inline';
			}
		</script>
		<tr id="Option" style="display:<%=providerClass==null||providerClass.equals("")?"inline":"none"%>">
			<td class=dataLabel width="15%" align="right"></td>
			<td class=dataField>
				<form action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="">
				<input type="submit" name="subt" value="&nbsp;提&nbsp;&nbsp;交&nbsp;">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				</form>
			</td>
			<td align="left">提交则取消短信集成</td>
		</tr>		
		<tr id="ShortOption" style="display:<%=providerClass.indexOf("web.Short")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">短信猫配置：</td>
			<td class=dataField>
				<form action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="Short">
				串口(port)：<input type="text" name="port" value="<%=PropertyFile.readValue("conf/gsmDeviceConnectionSettings.properties", "port") %>"><br>
				波特率(baudRate)：<input type="text" name="baudRate" value="<%=PropertyFile.readValue("conf/gsmDeviceConnectionSettings.properties", "baudRate") %>"><br>
				短信中心(smsCNum)：<input type="text" name="smsCNum" value="<%=PropertyFile.readValue("conf/gsmDeviceConnectionSettings.properties", "smsCNum") %>"><br>
				<input type="submit" name="subt" value="&nbsp;提&nbsp;&nbsp;交&nbsp;">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				</form>
			</td>
			<td align="left">主要支持WaveCom设备，配置文件为<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/gsmDeviceConnectionSettings.properties") %>&fileName=gsmDeviceConnectionSettings.properties">gsmDeviceConnectionSettings.properties</a></td>
		</tr>
		<tr id="XuanwuOption" style="display:<%=providerClass.indexOf("sms.impl.Xuanwu")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">玄武配置：</td>
			<td class=dataField>
<%			
	xmlFile = System.getProperty("oa_application.config") + "/conf/sendmsgconfig.xml";
	file = new File(xmlFile);
	Element sendMsgConfig = null;
	Element proxyserverinfo = null;
	try {
		doc = builder.build(file);
		sendMsgConfig = doc.getRootElement();
		proxyserverinfo = sendMsgConfig.getChild("proxyserverinfo");
	} catch (JDOMException e) {
		e.printStackTrace();
	} catch (IOException e) {
		e.printStackTrace();
	} catch (Exception e) {
		e.printStackTrace();
	}	
%>				
				<form action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="Xuanwu">
				网关地址(host)：<input type="text" name="host" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("host"):"" %>"><br>
				端口号(port)：<input type="text" name="port" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("port"):"" %>"><br>
				用户名,接口名(username)：<input type="text" name="username" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("username"):"" %>"><br>
				密码(password)：<input type="text" name="password" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("password"):"" %>"><br>
				Esms服务地址(serviceaddress)：<input type="text" name="serviceaddress" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("serviceaddress"):"" %>"><br>
				是否使用代理(useProxy)：<select size=1 name="useProxy"><option value="off" <% if ("off".equals(proxyserverinfo!=null?proxyserverinfo.getChildText("useProxy"):"")) { %>selected<% } %>>否</option><option value="on" <% if ("on".equals(proxyserverinfo!=null?proxyserverinfo.getChildText("useProxy"):"")) { %>selected<% } %>>是</option></select><br>
				代理服务器类型(proxyType)：<select size=1 name="proxyType"><option value="http" <% if ("http".equals(proxyserverinfo!=null?proxyserverinfo.getChildText("proxyType"):"")) { %>selected<% } %>>HTTP</option><option value="socks" <% if ("socks".equals(proxyserverinfo!=null?proxyserverinfo.getChildText("proxyType"):"")) { %>selected<% } %>>SOCKS</option></select><br>
				代理服务器IP(proxyIP)：<input type="text" name="proxyIP" value="<%=proxyserverinfo!=null?proxyserverinfo.getChildText("proxyIP"):"" %>"><br>
				代理服务器端口(proxyPort)：<input type="text" name="proxyPort" value="<%=proxyserverinfo!=null?proxyserverinfo.getChildText("proxyPort"):"" %>"><br>
				代理服务器用户名(proxyUser)：<input type="text" name="proxyUser" value="<%=proxyserverinfo!=null?proxyserverinfo.getChildText("proxyUser"):"" %>"><br>
				代理服务器密码(proxyPass)：<input type="text" name="proxyPass" value="<%=proxyserverinfo!=null?proxyserverinfo.getChildText("proxyPass"):"" %>"><br>
				<input type="submit" name="subt" value="&nbsp;提&nbsp;&nbsp;交&nbsp;">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				</form>
			</td>
			<td align="left">http://www.139130.net，<br>配置文件为<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/sendmsgconfig.xml") %>&fileName=sendmsgconfig.xml">sendmsgconfig.xml</a></td>
		</tr>	
		<tr id="IflyOption" style="display:<%=providerClass.indexOf("sms.impl.Ifly")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">金蝶IFly配置：</td>
			<td class=dataField>
				<form action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="Ifly">
				公司帐号(ifly.k_account)：<input type="text" name="k_account" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "ifly.k_account") %>"><br>
				公司密码(ifly.k_password)：<input type="text" name="k_password" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "ifly.k_password") %>"><br>
				关联帐号(ifly.k_source)：<input type="text" name="k_source" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "ifly.k_source") %>"><br>
				服务器端地址(ifly.k_host)：<input type="text" name="k_host" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "ifly.k_host") %>"><br>
				服务器端端口(ifly.k_port)：<input type="text" name="k_port" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "ifly.k_port") %>"><br>
				<input type="submit" name="subt" value="&nbsp;提&nbsp;&nbsp;交&nbsp;">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				</form>				
			</td>
			<td align="left">http://www.ifly.com.cn，<br>配置文件<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/smsconfig.properties") %>&fileName=smsconfig.properties">smsconfig.properties</a></td>
		</tr>
		<tr id="SouthSeaOption" style="display:<%=providerClass.indexOf("sms.impl.SouthSea")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">佛山南海配置：</td>
			<td class=dataField>
				<form action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="SouthSea">
				对方数据库连接url(host)：<input type="text" name="host" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("host"):"" %>"><br>
				用户名(username)：<input type="text" name="username" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("username"):"" %>"><br>
				密码(password)：<input type="text" name="password" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("password"):"" %>"><br>
				jdbc的驱动(serviceaddress)：<input type="text" name="serviceaddress" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("serviceaddress"):"" %>"><br>
				<input type="submit" name="subt" value="&nbsp;提&nbsp;&nbsp;交&nbsp;">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				</form>
			</td>
			<td align="left">配置文件为<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/sendmsgconfig.xml") %>&fileName=sendmsgconfig.xml">sendmsgconfig.xml</a>，<br>共用了玄武的配置文件</td>
		</tr>
		<tr id="JassonSoftOption" style="display:<%=providerClass.indexOf("sms.impl.JassonSoft")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">深圳嘉讯配置：</td>
			<td class=dataField>
				<form action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="JassonSoft">
				信息机的IP 地址(host)：<input type="text" name="host" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("host"):"" %>"><br>
				用户名,接口名(username)：<input type="text" name="username" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("username"):"" %>">使用,分隔<br>
				密码(password)：<input type="text" name="password" value="<%=sendMsgConfig!=null?sendMsgConfig.getChildText("password"):"" %>"><br>
				<input type="submit" name="subt" value="&nbsp;提&nbsp;&nbsp;交&nbsp;">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				</form>
			</td>
			<td align="left">http://www.jassonsoft.com，<br>配置文件为<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/sendmsgconfig.xml") %>&fileName=sendmsgconfig.xml">sendmsgconfig.xml</a>，<br>共用了玄武的配置文件</td>
		</tr>
		<tr id="MobsetOption" style="display:<%=providerClass.indexOf("sms.impl.Mobset")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">广州首易配置：</td>
			<td class=dataField>
				<form action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="Mobset">
				登录帐号(mobset.strLoginName)：<input type="text" name="strLoginName" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "mobset.strLoginName") %>"><br>
				登录密码(mobset.strPasswd)：<input type="text" name="strPasswd" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "mobset.strPasswd") %>"><br>
				公司号(mobset.iCorpID)：<input type="text" name="iCorpID" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "mobset.iCorpID") %>"><br>
				服务器端地址(mobset.strHost)：<input type="text" name="strHost" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "mobset.strHost") %>"><br>
				超时时间(mobset.iTimeOut)：<input type="text" name="iTimeOut" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "mobset.iTimeOut") %>"><br>
				<input type="submit" name="subt" value="&nbsp;提&nbsp;&nbsp;交&nbsp;">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				</form>	
			</td>
			<td align="left">http://www.mobset.com，<br>配置文件：<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/smsconfig.properties") %>&fileName=smsconfig.properties">smsconfig.properties</a></td>
		</tr>	
		<tr id="SurgeOption" style="display:<%=providerClass.indexOf("sms.impl.Surge")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">巨澜配置：</td>
			<td class=dataField>
				<form action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="Surge">
				发送机数据库url(surge.jdbc.url)：<input type="text" name="url" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "surge.jdbc.url") %>"><br>
				jdbc的驱动(surge.jdbc.driver)：<input type="text" name="driver" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "surge.jdbc.driver") %>"><br>
				数据库登录用户(surge.jdbc.dbname)：<input type="text" name="dbname" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "surge.jdbc.dbname") %>"><br>
				数据库登录密码(surge.jdbc.dbpass)：<input type="text" name="dbpass" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "surge.jdbc.dbpass") %>"><br>
				企业编号(surge.epid)：<input type="text" name="epid" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "surge.epid") %>"><br>
				企业帐号(surge.api.userid)：<input type="text" name="userid" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "surge.api.userid") %>"><br>
				企业密码(surge.api.pass)：<input type="text" name="pass" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "surge.api.pass") %>"><br>
				链接类型(surge.type)：<input type="text" name="type" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "surge.type") %>"><br>
				<input type="submit" name="subt" value="&nbsp;提&nbsp;&nbsp;交&nbsp;">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				</form>			
			</td>
			<td align="left">http://www.surge.com.cn，<br>配置文件：<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/smsconfig.properties") %>&fileName=smsconfig.properties">smsconfig.properties</a></td>
		</tr>
		<tr id="WeinaOption" style="display:<%=providerClass.indexOf("sms.impl.Weina")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">维那多配置：</td>
			<td class=dataField>
				<form id="weinaform" action="mobile_set.jsp" method="post">
				<input type="hidden" name="provider" value="Weina">
				公司帐号(weina.account)：<input type="text" name="weina.account" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "weina.account") %>"><br>
				公司密码(weina.password)：<input type="text" name="weina.password" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "weina.password") %>"><br>
				服务器端地址(weina.host)：<input type="text" name="weina.host" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "weina.host") %>"><br>
				服务器端接口(weina.method)：<input type="text" name="weina.method" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "weina.method") %>"><br>
				服务器编码(weina.charset)：<input type="text" name="weina.charset" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "weina.charset") %>"><br>
				<input type="button" name="subt" value="测试并提交" onclick="testWeiNaLink()">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				<!--  
				<input type="button" name="weinalink" value="测试连接" onclick="testWeiNaLink()">	
				-->
				</form>				
			</td>
			<td align="left">http://kingdee.weinaduo.net<br>配置文件<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/smsconfig.properties") %>&fileName=smsconfig.properties">smsconfig.properties</a></td>
		</tr>
		
		<tr id="YouShangOption" style="display:<%=providerClass.indexOf("sms.impl.YouShang")>0?"inline":"none" %>">
			<td class=dataLabel width="15%" align="right">金蝶友商配置：</td>
			<td class=dataField>
				<form id="youshangform"  action="mobile_set.jsp" method="post">	
				<input type="hidden" name="provider" value="YouShang">
				公司帐号(youshang.account)：<input type="text" name="youshang.account" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "youshang.account") %>"><br>
				公司密码(youshang.password)：<input type="text" name="youshang.password" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "youshang.password") %>"><br>
				服务器端地址(youshang.host)：<input type="text" name="youshang.host" value="<%=PropertyFile.readValue("conf/smsconfig.properties", "youshang.host") %>"><br>
				<input type="button" name="subt" value="测试并提交"  onclick="testYoushangLink()">
				<input type="reset" name="rest" value="&nbsp;重&nbsp;&nbsp;置&nbsp;">
				<!--  
				<input type="button" name="youshanglink" value="测试连接" onclick="testYoushangLink()">	
				-->
				</form>		
			</td>
			<td align="left">https://api.youshang.com<br>配置文件<a href="../application/file_download.jsp?filePath=<%=(System.getProperty("oa_application.config")+"/conf/smsconfig.properties") %>&fileName=smsconfig.properties">smsconfig.properties</a></td>
		</tr>														
	</table>
</body>
<script type="text/javascript">
function testYoushangLink(){
	var account = document.getElementById("youshang.account").value;
	var password = document.getElementById("youshang.password").value;
	var host = document.getElementById("youshang.host").value;
	if(null==account||account==''){
		alert('请先填写帐号!');
		return;
	}
	if(null==password||password==''){
		alert('请先填写帐号密码!');
		return;
	}
	if(null==host||host==''){
		alert('请先填写服务器地址!');
		return;
	}
	var ajaxUrl='<c:url value="/admin/comm.do?method=youshanglink"/>'+'&account='+account+'&password='+password+'&host='+host+'&random='+Math.random();
	new Ajax.Request(ajaxUrl, {
		async: false, 
		method:'post', 
		onSuccess:function(x){
			if(x.responseText=='true'){
				//分开写，不然youshangresult不一定能过去.
				//测试成功，跳转到mobile_set.jsp页面，走原来的逻辑.
				document.getElementById("youshangform").submit();	
			}else{
				//测试失败，跳转到mobile_check.jsp页面，走后面的逻辑.
				document.getElementById("youshangform").action =  "mobile_check.jsp?youshangresult=0";
				document.getElementById("youshangform").submit();	
			}
	}});
	
}

function testWeiNaLink(){
	var account = document.getElementById("weina.account").value;
	var password = document.getElementById("weina.password").value;
	var host = document.getElementById("weina.host").value;
	if(null==account||account==''){
		alert('请先填写帐号!');
		return;
	}
	if(null==password||password==''){
		alert('请先填写帐号密码!');
		return;
	}
	if(null==host||host==''){
		alert('请先填写服务器地址!');
		return;
	}
	var ajaxUrl='<c:url value="/admin/comm.do?method=weinalink"/>'+'&account='+account+'&password='+password+'&host='+host+'&random='+Math.random();
	new Ajax.Request(ajaxUrl, {
		async: false, 
		method:'post', 
		onSuccess:function(x){
			if(x.responseText=='true'){
				//document.getElementById("weinaform").action =  "mobile_check.jsp?weinaresult=1";
				document.getElementById("weinaform").submit();
			}else{
				document.getElementById("weinaform").action =  "mobile_check.jsp?weinaresult=0";
				document.getElementById("weinaform").submit();
			}
		}});
}
</script>
</html>
